
import 'package:flutter/material.dart';
import 'package:study_app/scenes/main_parts/custom_read_page.dart';
import 'package:study_app/scenes/main_parts/data_list.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);
  @override
  State<StatefulWidget> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("首页"),),
      body: Wrap(
          spacing: 5,
          runSpacing: 5,
          children: <Widget>[
            _buttonItem("跳转列表页"),
            _buttonItem("跳转列表页"),
            _buttonItem("跳转列表页"),
            _buttonItem("跳转列表页"),
            _buttonItem("跳转列表页"),
            _buttonItem("自定义")
          ],
        ),
    );
  }

  Widget _buttonItem(String btnText) {
    return TextButton(
        onPressed: () {
          if (btnText == "自定义") {
            _incrementCounter(page: const CustomReader(readText: ""));
          } else {
            _incrementCounter();
          }
        }, child: _buttonNodes(btnText));
  }

  void _incrementCounter({Widget? page}) {
    var nexPage = page ?? const DataList();
    Navigator.push(context,
        MaterialPageRoute(builder: (BuildContext context) => nexPage));
  }
  Widget _buttonNodes(String btnText) {
    return Container(
        decoration: _buttonDecoration(),
        width: 80,
        height: 80,
        alignment: Alignment.center,
        child: _buttonText(btnText));
  }

  BoxDecoration _buttonDecoration() {
    return BoxDecoration(
        color: Colors.white, borderRadius: BorderRadius.circular(5));
  }

  Text _buttonText(String btnText) {
    return Text(btnText, style: const TextStyle(color: Color(0xff333333)));
  }
}